package com.yxlcommon.common.pojo;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import com.yxlcommon.common.mapper.DemandsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

/**
 * @author: yxl
 * @since: 2021-12-23
 **/
@Component
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

    @Autowired
    private DemandsMapper demandsMapper;
    private Demands demands;
    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern){
        String expiredKey = message.toString();
        if (expiredKey.contains("demandId")){
            String demandId = expiredKey.substring(8, expiredKey.length());
            demandsMapper.update(demands,new UpdateWrapper<Demands>().eq("status",1).eq("demand_id",demandId).set("status",4));
        }
    }
}
